package com.xjgc.webservice;

import com.alibaba.fastjson.JSON;
import com.xjgc.msibase.entity.MsiServerRecord;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @author: 小逗号
 * @date: 2023-10-25
 * @description:
 * @since:
 */
@Data
public abstract class XParam implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 获取参数中有效数据
     *
     * @return
     */
    protected abstract List<?> dataList();

    public JSON dataAsJson() {
        List<?> dataList = this.dataList();
        if (CollectionUtils.isEmpty(dataList)) {
            return null;
        }
        Object obj = JSON.toJSON(dataList);
        JSON o = (JSON) obj;
        return o;
    }

    public String dataAsXml(MsiServerRecord record) {
        List<?> dataList = this.dataList();
        if (CollectionUtils.isEmpty(dataList)) {
            return null;
        }
        String xml = XmlUtils.toXml(record, this);
        return xml;
    }


}
